﻿using System;
using System.IO;
using System.Reflection;
using BSpec.Conventions;
using BSpec.Specification;

namespace BSpec.Document
{
    public class DocumentGenerator
    {
        private readonly IDocumentRenderer _documentRenderer;

        public DocumentGenerator(IDocumentRenderer documentRenderer)
        {
            _documentRenderer = documentRenderer;
        }

        public void WriteDocument(Assembly specAssembly)
        {
            SpecificationDataSet specificationDataset = SpecificationDataSet.Build(specAssembly);

            string generatedDocument = _documentRenderer.Render(specificationDataset);

            string documentFilePath = specAssembly.GetName().Name + _documentRenderer.FileExtension;

            TextWriter writer = new StreamWriter(documentFilePath);

            writer.Write(generatedDocument);
            writer.Close();
        }
    }
}
